package com.bryantkobe.myspringcode.service.impl;

import com.bryantkobe.myspringcode.entity.Customer;
import com.bryantkobe.myspringcode.mapper.CustomerMapper;
import com.bryantkobe.myspringcode.service.IPostgreSQLService;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import static com.bryantkobe.myspringcode.entity.table.CustomerTableDef.CUSTOMER;

/**
 * @description: PostgreSQL服务实现类
 * @author: alienwarezzl
 * @date: 2025/9/17
 */
@Service
public class IPostgreSQLServiceImpl implements IPostgreSQLService {

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public Boolean insertCustomer(Customer customer) {

        int insert = customerMapper.insert(customer);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Boolean deleteCustomerByCustomerId(Integer customerId) {
        QueryWrapper deleteQueryWrapper = QueryChain.of(customerMapper)
                .where(CUSTOMER.CUSTOMER_ID.eq(customerId))
                .toQueryWrapper();
        int i = customerMapper.deleteByQuery(deleteQueryWrapper);
        return i > 0;
    }
}
